<template>
  <h3 style="margin-bottom: 20px">订单查询</h3>
  <el-table :data="orderRef"
            border
            style="width: 70vw;margin-top: 20px"
  >
    <el-table-column type="index" width="50"/>
    <el-table-column prop="memberId" label="会员ID/客户ID"/>
    <el-table-column prop="content" label="订单内容"/>
    <el-table-column prop="totalPrice" label="总价"/>
    <el-table-column prop="score" label="评分"/>
    <el-table-column prop="time" label="订单生成时间"/>
  </el-table>
</template>

<script setup>
import {onMounted, ref} from "vue";
import {listOrderApi} from "../../api";

let orderRef = ref(null)
onMounted(async () => {
  let orders = await (await listOrderApi()).json()
  for (let i = 0; i < orders.data.length; i++) {
    orders.data[i].content = orders.data[i].content.split(", ").map(item => item.split("-")[1]).join(", ")
    let str = orders.data[i].time
    let date = new Date(str);
    let year = date.getFullYear();
    let month = ("0" + (date.getMonth() + 1)).slice(-2);
    let day = ("0" + date.getDate()).slice(-2);
    let hours = ("0" + date.getHours()).slice(-2);
    let minutes = ("0" + date.getMinutes()).slice(-2);
    let seconds = ("0" + date.getSeconds()).slice(-2);

    orders.data[i].time = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
  }
  orderRef.value = orders.data
  // orderRef.value.content = orderRef.value.content.split(", ").map(item => item.split("-")[1]).join(", ")
})
</script>

<style scoped>

</style>